<?php

use yii\helpers\Html;
//use yii\bootstrap\ActiveForm;
use anruence\editormd\EditorMd;
//use common\widgets\ueditor\Ueditor;
use common\widgets\ueditor\Ueditor;
use common\widgets\avatar\AvatarWidget;
use common\widgets\avatar\AvatarViewWidget;
use yii\widgets\ActiveForm;
use janisto\timepicker\TimePicker;
use yii\helpers\ArrayHelper;

?>
<div class='blog-form'>
    <?= AvatarWidget::widget(['imageUrl'=>'']); ?>
    <?php $form = ActiveForm::begin([
        'options' => ['enctype' => 'multipart/form-data', 'id' => "news-flash-post"],]) ?>

    <?= $form->field($model, 'title')->textInput(['maxlength' => true]) ?>
    <div>
        <div style="float: left;" class="image-widght">
            <?= $form->field($model, 'image')->widget(AvatarViewWidget::className(),['imageUrl'=>'/images/webuse.jpg']) ?>
        </div>
        <div style="width: 300px;float: left;">
        <?= $form->field($model, 'summary')->textarea(['row' => 5,'col' => 100,'style'=>"width:600px;height:80px;"]) ?>
        </div>
        <div class="clearfix"></div>
    </div>
    <?= $form->field($model, 'authorid')->dropDownList($usermaps); ?>
    <?= $form->field($model, 'tags')->textarea(['maxlength' => true]) ?>
    <?= $form->field($model, 'content')->widget(Ueditor::className(), ['options'=>['lang' =>'zh-cn','initialFrameWidth' => '100%','initialFrameHeight' => 400]]);?>
    <?= $form->field($model, 'status')->radioList(['2' => '草稿', '3' => '定时发布', '0' => '立即发布'])->label('发布方式'); ?>
    <?= $form->field($model, 'ptime')->widget(TimePicker::className(), [
        //'language' => 'fi',
        'options' => ['placeholder' => 'Publish time','style' => 'width:300px;'],
        'mode' => 'datetime',
        'clientOptions'=>[
            'dateFormat' => 'yy-mm-dd',
            'timeFormat' => 'HH:mm:ss',
            'showSecond' => true,
            'defaultTime' => date("H:i:s",time()),
            'minDate' => date("Y-m-d H:i:s",time())
        ]
    ])->label("发布时间");?>
    <div class='form-group field-blog-submit'>
        <?= Html::a('预览', ['/newsnom/viewbefore','data-id' => $model->isNewRecord ? 0 : $model->id,'type' => 2], [
            'title' => Yii::t('yii', '提交前预览'),
            'class' => 'btn btn-default',
            'role' => 'modal-remote',
        ]) ?>
        <?= Html::submitButton($model->isNewRecord ? '确认发布' : '确认修改', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
    </div>
    <?php ActiveForm::end(); ?>
</div>
<script src="/js/tags/jquery.tag-editor.js"></script>
<link rel="stylesheet" href="/js/tags/jquery.tag-editor.css">
<script type="text/javascript">
    userAspectRatio = 16 / 9;
    function googleSuggest(request, response) {
        var term = request.term;
        if (term in cache) { response(cache[term]); return; }
        $.ajax({
            url: 'http://query.yahooapis.com/v1/public/yql',
            dataType: 'JSONP',
            data: { format: 'json', q: 'select * from xml where url="http://google.com/complete/search?output=toolbar&q='+term+'"' },
            success: function(data) {
                var suggestions = [];
                try { var results = data.query.results.toplevel.CompleteSuggestion; } catch(e) { var results = []; }
                $.each(results, function() {
                    try {
                        var s = this.suggestion.data.toLowerCase();
                        suggestions.push({label: s.replace(term, '<b>'+term+'</b>'), value: s});
                    } catch(e){}
                });
                cache[term] = suggestions;
                response(suggestions);
            }
        });

    }
    $(function(){
        $(".field-newsnom-ptime").hide();
        var _status = $("input[name='NewsNom[status]']:checked").val();
        if( _status == 3 ){
            $(".field-newsnom-ptime").show();
        }
        $("input[name='NewsNom[status]']").change(function () {
            if( $(this).val() == 3 ){
                $(".field-newsnom-ptime").show();
            }else{
                $(".field-newsnom-ptime").hide();
                $("#newsnom-ptime").val("");
            }
        });

        $('#newsnom-tags').tagEditor();
    });

</script>

